<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<title>Slider Tests</title>
<link href="css/test.css" rel="stylesheet"/>
<script type="text/javascript" src="../../deviceTheme.js"></script>
<script type="text/javascript" src="../../../../dojo/dojo.js" data-dojo-config="async: true, parseOnLoad: true"></script>
<script language="JavaScript" type="text/javascript">
require([
	"dojo/dom-construct", // dojo.place
	"dojo/dom-class", // dojo.hasClass
	"dojo/ready", // dojo.ready
	"dijit/registry",  // dijit.byId
	"doh/runner",	//doh functions
	"dojox/mobile/Slider",
	"dojox/mobile",				// This is a mobile app.
	"dojox/mobile/View",		// This mobile app uses mobile view
	"dojox/mobile/compat",		// This mobile app supports running on desktop browsers
	"dojox/mobile/parser"		// This mobile app uses declarative programming with fast mobile parser
], function(domConst, domClass, ready, registry, runner, Slider){

	var WIDGET_CLASSNAME1 = "mblSlider";
	var WIDGET_VALUE = "31.4";
	var WIDGET_VALUE2 = WIDGET_VALUE + "%";

	function _createSliderDeclaratively(widgetId) {
		return registry.byId(widgetId);
	};

	function _createSliderProgrammatically(placeHolderId, widgetId){
		var r = new Slider({id:widgetId, name:"sh2", value:"31.4", min:"0", max:"100", step:"0.1", type:"range", style:"width:150px"});
		runner.assertNotEqual(null, r);
		dojo.place(r.domNode, placeHolderId, "replace");
		r.startup();
		
		return r;
	};

	function _createSliderProgrammaticallyWithSourceNodeReference(widgetId){
		// Create IconContainer
		var r = new Slider({}, widgetId);
		r.startup();

		return r;
	};



	function _assertCorrectSlider(widget, noIcon, rightIcon, rightIcon2, rightText, boxText){
		runner.assertNotEqual(null, widget, "Slider: Did not instantiate. id=" + widget.domNode.id);
		runner.assertTrue(domClass.contains(widget.domNode, WIDGET_CLASSNAME1), WIDGET_CLASSNAME1 + " id=" + widget.domNode.id);
		runner.assertEqual(WIDGET_VALUE, widget.valueNode.value);
		runner.assertEqual(WIDGET_VALUE, widget.get('value'));
		runner.assertEqual(WIDGET_VALUE2, widget.progressBar.style.width);
		runner.assertEqual(WIDGET_VALUE2, widget.handle.style.left);
	};

	function _showView2(){
		var view1 = registry.byId("view1");
		view1.performTransition("view2", 1, "none");
	};

	ready(function(){
		runner.register("dojox.mobile.test.doh.Slider", [
			{
				name: "Slider Verification1",
				timeout: 4000,
				runTest: function(){
					var widget1 = _createSliderDeclaratively("view1-Slider1");
					var widget2 = _createSliderProgrammatically("view1-Slider2Place", "view1-Slider2");
					var widget3 = _createSliderProgrammaticallyWithSourceNodeReference("view1-Slider3");

					_assertCorrectSlider(widget1);
					_assertCorrectSlider(widget2);
//					_assertCorrectSlider(widget3);
				}
			},
			{
				name: "Slider Verification2",
				timeout: 4000,
				runTest: function(){
					var widget1 = _createSliderDeclaratively("view2-Slider1");
					var widget2 = _createSliderProgrammatically("view2-Slider2Place", "view2-Slider2");
					var widget3 = _createSliderProgrammaticallyWithSourceNodeReference("view2-Slider3");

					var d = new runner.Deferred();
					var handle2 = dojo.subscribe("/dojox/mobile/afterTransitionIn", d.getTestCallback(function(view){
						if(view.id=="view2"){
							dojo.unsubscribe(handle2);
						}
						_assertCorrectSlider(widget1);
						_assertCorrectSlider(widget2);
//						_assertCorrectSlider(widget3);
					}));
					_showView2();
					return d;
				}
			}
		]);
		runner.run();
	});
})
</script>
</head>
<body style="visibility:hidden;">
	<div id="view1" data-dojo-type="dojox.mobile.View" data-dojo-props='selected:"true"'>
		<h1>View1</h1>
		<table>
			<tr>
				<td>0</td>
				<td><input id="view1-Slider1" data-dojo-type="dojox.mobile.Slider" name="sh1" value="31.4" min="0" max="100" step="0.1" type="range" style="width:150px;"></td>
				<td>100</td>
			</tr>
		</table>
		<table>
			<tr>
				<td>0</td>
				<td><div id="view1-Slider2Place"></div></td>
				<td>100</td>
			</tr>
		</table>
		<table>
			<tr>
				<td>0</td>
				<td><input id="view1-Slider3" name="sh3" value="31.4" min="0" max="100" step="0.1" type="range" style="width:150px;"></td>
				<td>100</td>
			</tr>
		</table>
	</div>
	<div id="view2" data-dojo-type="dojox.mobile.View">
		<h1>View2</h1>
		<table>
			<tr>
				<td>0</td>
				<td><input id="view2-Slider1" data-dojo-type="dojox.mobile.Slider" name="sh1" value="31.4" min="0" max="100" step="0.1" type="range" style="width:150px;"></td>
				<td>100</td>
			</tr>
		</table>
		<table>
			<tr>
				<td>0</td>
				<td><div id="view2-Slider2Place"></div></td>
				<td>100</td>
			</tr>
		</table>
		<table>
			<tr>
				<td>0</td>
				<td><input id="view2-Slider3" name="sh3" value="31.4" min="0" max="100" step="0.1" type="range" style="width:150px;"></td>
				<td>100</td>
			</tr>
		</table>
	</div>
</body>
</html>
